//CardManager.java - Managing playing cards
import java.io.Serializable;

public class CardManager implements Serializable{
  	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	Card[] deck;
  	private int cardsUsed;
    private int tableNumber;

	public CardManager(int tableNumber) {
		this.tableNumber = tableNumber;
	    cardsUsed = 0;

	   deck = new Card[52];
	   for (int i = 0; i < deck.length; i++)
	      deck[i] = new Card(new CardSuit(i / 13 + 1),new CardValue(i % 13 + 1));
	 }


	public void shuffle() {
	    for (int i = 0; i < deck.length; i++){
	      	int k = (int)(Math.random() * 52);
	      	Card t = deck[i];
	      	deck[i] = deck[k];
	      	deck[k] = t;
    	}

   		cardsUsed = 0;
  	}

 	public int cardsLeft() {
          // As cards are dealt from the deck, the number of cards left
          // decreases.  This function returns the number of cards that
          // are still left in the deck.
        return 52 - cardsUsed;
    }

    public Card dealCard() {
          // Deals one card from the deck and returns it.
        cardsUsed++;
        return deck[cardsUsed - 1];
    }

    public Card[] getHoleCards() {
		Card[] holeCards= new Card[2];
		holeCards[0] = dealCard(); //Get first hole card
		holeCards[1] = dealCard(); //Get second hole card
		return holeCards;
    }

    public Card[] getFlopCards() {
		Card[] FlopCards= new Card[3];
		FlopCards[0] = dealCard(); //Get first flop card
		FlopCards[1] = dealCard(); //Get second flop card
		FlopCards[2] = dealCard(); //Get third flop card
		return FlopCards;
    }

    public Card getTurnCard() {
		Card TurnCard= new Card();
		TurnCard = dealCard(); //Get turn card
		return TurnCard;
    }

    public Card getRiverCard() {
		Card RiverCard= new Card();
		RiverCard = dealCard(); //Get river card
		return RiverCard;
    }


}
